class ImprovementsController < ApplicationController
  before_filter :login_required, :except => [:show]
  
  def authorized?(user = current_player())
    return user.admin?
  end
  
  # GET /improvements
  # GET /improvements.xml
  def index
    @improvements = Improvement.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @improvements }
    end
  end

  # GET /improvements/1
  # GET /improvements/1.xml
  def show
    @improvement = Improvement.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @improvement }
    end
  end

  # GET /improvements/new
  # GET /improvements/new.xml
  def new
    @improvement = Improvement.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @improvement }
    end
  end

  # GET /improvements/1/edit
  def edit
    @improvement = Improvement.find(params[:id])
  end

  # POST /improvements
  # POST /improvements.xml
  def create
    @improvement = Improvement.new(params[:improvement])

    respond_to do |format|
      if @improvement.save
        flash[:notice] = 'Improvement was successfully created.'
        format.html { redirect_to(@improvement) }
        format.xml  { render :xml => @improvement, :status => :created, :location => @improvement }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @improvement.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /improvements/1
  # PUT /improvements/1.xml
  def update
    @improvement = Improvement.find(params[:id])

    respond_to do |format|
      if @improvement.update_attributes(params[:improvement])
        flash[:notice] = 'Improvement was successfully updated.'
        format.html { redirect_to(@improvement) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @improvement.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /improvements/1
  # DELETE /improvements/1.xml
  def destroy
    @improvement = Improvement.find(params[:id])
    @improvement.destroy

    respond_to do |format|
      format.html { redirect_to(improvements_url) }
      format.xml  { head :ok }
    end
  end
end
